package com.itheima.Mapper;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClazzMapper {
    // 分页查询班级
   // @Select("select c.*,e.name as master_name from clazz c left join emp e  on c.master_id=e.id")
    List<Clazz> fenyelist(ClazzQueryParam clazzQueryParam);

    // 添加班级（注意：你的 add 方法缺少参数，下面会补充）
    @Insert("INSERT INTO clazz(name, room, begin_date, end_date, master_id, subject, create_time, update_time) " + "VALUES(#{name}, #{room}, #{beginDate}, #{endDate}, #{masterId}, #{subject}, #{createTime}, #{updateTime}) ")
    Integer add(Clazz clazz);  // 需要传入一个 Clazz 对象作为参数

    // 修改班级（缺少参数，下面会补充）
    @Update("UPDATE clazz SET name=#{name}, room=#{room}, begin_date=#{beginDate}, end_date=#{endDate}, master_id=#{masterId} " +
            "WHERE id=#{id}")  // 通常修改需要根据 id 来定位记录



    Integer update(Clazz clazz);  // 需要传入一个 Clazz 对象作为参数

    // 查询所有班级
    @Select("SELECT * FROM clazz")
    List<Clazz> list();

    @Select("SELECT * FROM clazz WHERE id = #{id}")
    Clazz getById(Integer id);  // 注意：根据 id 查询返回 List 不太合理，建议返回单个对象 Clazz

    @Delete("DELETE FROM clazz WHERE id = #{id}")
    Integer delete(Integer id);

 /*   @Select("SELECT " +
            "c.*, " +
            "e.name as master_name, " +
            "(CASE WHEN NOW() < c.begin_date THEN '未开班' " +
            "      WHEN NOW() > c.end_date THEN '已结课' " +
            "      ELSE '在读' " +
            "END) as status " +
            "FROM clazz c LEFT JOIN emp e ON c.master_id = e.id")
    List<Clazz> getStatus();*/


}